//
//  filterTree.h
//  map-matching
//
//  Created by Lv Xin on 16/5/10.
//  Copyright © 2016年 Lv Xin. All rights reserved.
//
//  Personal Homepage: www.davidlvxin.com

#ifndef filterTree_h
#define filterTree_h

#include "filterStrategy.h"
#include <stdio.h>
#include <queue>

struct RouteWithSima{
    Route* m;
    double simA;
    RouteWithSima(Route* a);
    ~RouteWithSima(){}
};

struct cmp{//优先级队列的比较函数
    bool operator () (RouteWithSima *x, RouteWithSima *y){
        return x->simA > y->simA;
    }
};

struct TreeNode{
    int deep;//深度,根节点深度取-1
    int rank;//第几个儿子
    bool canUse;
    TreeNode* parent;
    Route* route;
    double lenthSoFar;
    TreeNode* child[S];
    TreeNode(int d, int r, TreeNode* p);
    ~TreeNode();
};

class FilterTree : public FilterStrategy{
    Map* mapSet;
    Trajectary& traj;
    std::priority_queue<RouteWithSima*, std::vector<RouteWithSima*>, cmp> PQCandidate;
    TreeNode* root;
    double R1SimB;
public:
    FilterTree(Trajectary& T, Map*);
    ~FilterTree();
    void computeR1SimB();
    void cutOff() = 0;
    void insertNode(RouteWithSima* a);
    void outputToList(TreeNode*);
    void deleteTreeNode(TreeNode*);
    std::string strategyName();
};

#endif /* filterTree_h */
